package com.jdaw.datastructure.search;

public class InsertValueSearch {
    public static void main(String[] args) {
        int[] arr=new int[100];
        for(int i=0;i<arr.length;i++){
            arr[i]=i+1;
        }
        System.out.println(insertValueSearch(arr,0,arr.length-1,1));
    }

    public static int insertValueSearch(int[] arr,int left,int right,int findVal){
        //没有找到的情况
        if(left>right||findVal<arr[0]||findVal>arr[arr.length-1]){
            return -1;
        }

        System.out.println("0");
        int mid=left+(right-left)*(findVal-arr[left])/(arr[right]-arr[left]);
        if(arr[mid]<findVal){
            return insertValueSearch(arr,mid+1,right,findVal);
        }else if(arr[mid]>findVal){
            return insertValueSearch(arr,left,mid-1,findVal);
        }else {
            return mid;
        }
    }


}
